package cn.gson.springmvc.model.pojos;

import javax.persistence.*;
import java.util.Collection;
import java.util.Objects;

@Entity
public class Drug {
    private int drugId;
    private String drugName;
    private String drugSpecification;
    private String unit;
    private Long purchasingPrice;
    private Long sellingPrice;
    private String productionDate;
    private String validDate;
    private String site;
    private Supplier supplierBySupplierId;
    private Type typeByTypeId;
    private Collection<Drugapply> drugappliesByDrugId;
    private Collection<IndentDetailsOutbound> indentDetailsOutboundsByDrugId;
    private Collection<Inventory> inventoriesByDrugId;

    @Id
    @Column(name = "drug_id", nullable = false)
    public int getDrugId() {
        return drugId;
    }

    public void setDrugId(int drugId) {
        this.drugId = drugId;
    }

    @Basic
    @Column(name = "drug_name", nullable = true, length = 30)
    public String getDrugName() {
        return drugName;
    }

    public void setDrugName(String drugName) {
        this.drugName = drugName;
    }

    @Basic
    @Column(name = "drug_specification", nullable = true, length = 30)
    public String getDrugSpecification() {
        return drugSpecification;
    }

    public void setDrugSpecification(String drugSpecification) {
        this.drugSpecification = drugSpecification;
    }

    @Basic
    @Column(name = "unit", nullable = true, length = 20)
    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    @Basic
    @Column(name = "purchasing_price", nullable = true, precision = 0)
    public Long getPurchasingPrice() {
        return purchasingPrice;
    }

    public void setPurchasingPrice(Long purchasingPrice) {
        this.purchasingPrice = purchasingPrice;
    }

    @Basic
    @Column(name = "selling_price", nullable = true, precision = 0)
    public Long getSellingPrice() {
        return sellingPrice;
    }

    public void setSellingPrice(Long sellingPrice) {
        this.sellingPrice = sellingPrice;
    }

    @Basic
    @Column(name = "production_date", nullable = true, length = 30)
    public String getProductionDate() {
        return productionDate;
    }

    public void setProductionDate(String productionDate) {
        this.productionDate = productionDate;
    }

    @Basic
    @Column(name = "valid_date", nullable = true, length = 30)
    public String getValidDate() {
        return validDate;
    }

    public void setValidDate(String validDate) {
        this.validDate = validDate;
    }

    @Basic
    @Column(name = "site", nullable = true, length = 30)
    public String getSite() {
        return site;
    }

    public void setSite(String site) {
        this.site = site;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Drug drug = (Drug) o;
        return drugId == drug.drugId &&
                Objects.equals(drugName, drug.drugName) &&
                Objects.equals(drugSpecification, drug.drugSpecification) &&
                Objects.equals(unit, drug.unit) &&
                Objects.equals(purchasingPrice, drug.purchasingPrice) &&
                Objects.equals(sellingPrice, drug.sellingPrice) &&
                Objects.equals(productionDate, drug.productionDate) &&
                Objects.equals(validDate, drug.validDate) &&
                Objects.equals(site, drug.site);
    }

    @Override
    public int hashCode() {
        return Objects.hash(drugId, drugName, drugSpecification, unit, purchasingPrice, sellingPrice, productionDate, validDate, site);
    }



    @ManyToOne
    @JoinColumn(name = "supplier_id", referencedColumnName = "supplier_id")
    public Supplier getSupplierBySupplierId() {
        return supplierBySupplierId;
    }

    public void setSupplierBySupplierId(Supplier supplierBySupplierId) {
        this.supplierBySupplierId = supplierBySupplierId;
    }

    @ManyToOne
    @JoinColumn(name = "type_id", referencedColumnName = "type_id")
    public Type getTypeByTypeId() {
        return typeByTypeId;
    }

    public void setTypeByTypeId(Type typeByTypeId) {
        this.typeByTypeId = typeByTypeId;
    }


    @OneToMany(mappedBy = "drugByDrugId")
    public Collection<Drugapply> getDrugappliesByDrugId() {
        return drugappliesByDrugId;
    }

    public void setDrugappliesByDrugId(Collection<Drugapply> drugappliesByDrugId) {
        this.drugappliesByDrugId = drugappliesByDrugId;
    }

    @OneToMany(mappedBy = "drugByDrugId")
    public Collection<IndentDetailsOutbound> getIndentDetailsOutboundsByDrugId() {
        return indentDetailsOutboundsByDrugId;
    }

    public void setIndentDetailsOutboundsByDrugId(Collection<IndentDetailsOutbound> indentDetailsOutboundsByDrugId) {
        this.indentDetailsOutboundsByDrugId = indentDetailsOutboundsByDrugId;
    }

    @OneToMany(mappedBy = "drugByDrugId")
    public Collection<Inventory> getInventoriesByDrugId() {
        return inventoriesByDrugId;
    }

    public void setInventoriesByDrugId(Collection<Inventory> inventoriesByDrugId) {
        this.inventoriesByDrugId = inventoriesByDrugId;
    }
}
